<template>
	<div>
		<div class="box">
			<div class="title">
				<span class="tag"></span>
				更换承租方
			</div>
			<AForm
				ref="form"
				v-model="formData"
				:config="formList"
				:layout="{ column: true }"
				:state="state"></AForm>
		</div>
	</div>
</template>

<script>
	import AForm from '@/components/A/A-form/form/index.vue';
	export default {
		name: '',
		components: { AForm },
		props: {
			value: {
				type: Object,
				default: () => {
					return {};
				},
			},
			state: {
				required: false,
			},
		},
		data() {
			return {
				dictList: {
					returnMargin: [
						{
							label: '是',
							value: '1',
						},
						{
							label: '否',
							value: '2',
						},
					],
				},
			};
		},
		computed: {
			formData: {
				get() {
					return this.useVModel.call(this);
				},
				set(val) {
					this.$emit('input', val);
				},
			},
			formList() {
				return [
					{
						label: '承租方',
						type: 'select_dialog',
						prop: 'leaseeId',
						propLabel: 'leaseeName',
						state: 'readonly',
						selectDialogOptions: {
							type: 'userNo',
							cb: ({ data, row }) => {
								row.leaseeId = data.customerId;
								row.leaseeName = data.customerName;
							},
						},
					},
					{
						label: '更换承租方',
						type: 'select_dialog',
						prop: 'newLeaseeId',
						propLabel: 'newLeaseeName',
						selectDialogOptions: {
							type: 'userNo',
							success: ({ data, row }) => {
								if (row.leaseeId !== data.customerId) {
									row.newLeaseeId = data.customerId;
									row.newLeaseeName = data.customerName;
								} else {
									this.$message({
										message: '新旧承租方不能为一样！',
										type: 'warning',
									});
									row.newLeaseeId = undefined;
									row.newLeaseeName = undefined;
								}
							},
						},
						rules: true,
					},
					{
						type: 'select',
						prop: 'returnMargin',
						label: '是否退保证金',
						dict: {
							list: this.dictList.returnMargin,
						},
						rules: true,
					},
				];
			},
		},
		created() {
			this.initDefaultData();
		},

		mounted() {},
		methods: {
			initDefaultData() {
				this.formData.returnMargin ??= '2';
			},
			setDefaultData() {
				this.formData.newLeaseeId = undefined;
				this.formData.returnMargin = undefined;
			},
		},
		beforeDestroy() {
			this.setDefaultData();
		},
	};
</script>

<style lang="scss" scoped>
	.box {
		border-radius: 8px;
		background-color: #fff;
		.title {
			font-size: 14px;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 22px;
			padding-top: 15px;
			padding-bottom: 15px;
			// border-bottom: 1px solid #e9e9e9;
			display: flex;
			align-items: center;
			.tag {
				width: 8px;
				height: 8px;
				background-color: #1890ff;
				border-radius: 100%;
				margin-right: 10px;
			}
			.price {
				font-size: 14px;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #1890ff;
				line-height: 20px;
				margin-left: 20px;
			}
		}
	}
</style>
